import 'dart:async';

import 'package:flutter/services.dart';

class Screen {
  static const CHANNEL = 'github.com/clovisnicolas/flutter_screen';
  static const EVENT = 'github.com/clovisnicolas/flutter_screen/event';
  static const REJECT = "REJECT";
  static const ACCEPT = "ACCEPT";
  static const DISABLE_KEYGUARD = "android.permission.DISABLE_KEYGUARD";
  static const SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW";
  static const OP_BACKGROUND_START_ACTIVITY = 10021;

  static const MethodChannel _channel = const MethodChannel(CHANNEL);
  static const EventChannel eventChannel = const EventChannel(EVENT);

  static Future<double> get brightness async => (await _channel.invokeMethod('brightness')) as double;
  static Future setBrightness(double brightness) =>_channel.invokeMethod('setBrightness',{"brightness" : brightness});
  static Future<bool> get isKeptOn async => (await _channel.invokeMethod('isKeptOn')) as bool;
  static Future keepOn(bool on) => _channel.invokeMethod('keepOn', {"on" : on});

  static Future<bool> acquireWakeLock() async => (await _channel.invokeMethod('acquireWakeLock')) as bool;
  static Future<bool> releaseWakeLock() async => (await _channel.invokeMethod('releaseWakeLock')) as bool;
  static Future wakeUpAndUnlock() =>  _channel.invokeMethod('wakeUpAndUnlock');

  static Future callingIn({ String name, String tips}) =>  _channel.invokeMethod('callingIn', {"name" : name, "tips": tips});
  static Future callConnected() =>  _channel.invokeMethod('callConnected');

  static Future registerCallingInReceiver() =>  _channel.invokeMethod('registerCallingInReceiver');
  static Future unregisterCallingInReceiver() =>  _channel.invokeMethod('unregisterCallingInReceiver');
  static Future<bool> hasPermission(String permission) async => (await _channel.invokeMethod("hasPermission", { "permission": permission }));
  static Future<bool> hasOpPermission(int op) async => (await _channel.invokeMethod("hasOpPermission", { "op": op }));
  static Future<bool> get canDrawOverlays async => (await _channel.invokeMethod("canDrawOverlays"));
  static Future<bool> hasPermissions(List<String> permissions) async => (await _channel.invokeMethod("hasPermissions", { "permissions": permissions }));
  static Future ignoreBatteryOptimization() => _channel.invokeMethod('ignoreBatteryOptimization');
}
